home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-01-12 | 4.3 KB | 136 lines | [TEXT/ToyS] |
- property dbName : "DD Address Book"
- property dbDesc : [¬
- {name:"Last name", style:text field, width:20}, ¬
- {name:"First name", style:text field, width:20}, ¬
- {name:"Street address", style:text field, width:20}, ¬
- {name:"City", style:text field, width:20}, ¬
- {name:"County", style:text field, width:20}, ¬
- {name:"Post Code", style:text field, width:10}, ¬
- {name:"Company affiliation", style:text field, width:20}, ¬
- {name:"Work phone#", style:text field, width:20}, ¬
- {name:"Home phone#", style:text field, width:20}, ¬
- {name:"Fax phone#", style:text field, width:20} ¬
- ]
- --{name:"Test Field", style:text field, width:10}, ¬
- property dbButtons : ["Store", "New", "Find", "Prev", "Next"]
- property dbFonts : [{name:"Geneva", size:9, style:plain}]
- property dbData : [¬
- "Hyde Chris 1701 Enterprise Street London Babylon 5 DS9 TNG HyLight BBC2, 6.00pm, Wednesday Channel 4, 10.30pm BBC2, 6.30pm, Sunday", ¬
- "1 2 3 4 5 6 7 8 9 10", ¬
- "0 1 2 3 4 5 6 7 8 9"]
- property dbNewRec : "a b c d e f g h i j"
-
- property nameWidth : 0
- property winH : 0
- property winV : 0
- property nWidth : 0
- property lineV : 20
- property lineCount : 0
-
- set nWidth to 8 -- width of "m" font font0's name size (font0's size) face font0's style
- if nameWidth = 0 then
- repeat with f in dbDesc
- set w to 8 + (f's name's length) * 5 -- (width of f's name font font0's name size (font0's size) face font0's style)
- if w > nameWidth then set nameWidth to w
- end repeat
- end if
- if winH = 0 then
- repeat with f in dbDesc
- set w to f's width
- if w > winH then set winH to w
- end repeat
- set winH to 20 + nameWidth + winH * nWidth
- set w to 10 + (dbButtons's length) * 60
- if w > winH then set winH to w
- end if
- set lineCount to (dbDesc's length) + 2
- if winV = 0 then set winV to lineCount * lineV + 20
-
- set dItems to []
- repeat with i from 1 to dbButtons's length
- set dItems to dItems & [MakeButton(dbButtons's item i, i)]
- end repeat
- --set dItems to dItems & [MakeButton(dbButtons's item i, i)]
- set y to 10 + (lineCount - 2) * lineV
- set dItems to dItems & [{class:static text, contents:"#", bounds:[winH - 100, y, winH - 10, y + 16], justification:right}]
-
- set y to 0
- repeat with f in dbDesc
- set dItems to dItems & [Field(f, y)]
- set y to y + 1
- end repeat
-
- global idx
- set idx to 1
- set recCount to dbData's length
- --get dd auto dialog {size:[winH, winV], name:dbName, style:movable modal, contents:dItems, font:font0} with greyscale
- dd install with fonts dbFonts with grayscale
- set d to dd make dialog {size:[winH, winV], name:dbName, style:standard window, contents:dItems, closeable:true}
- GetRecord(idx, d)
- repeat
- dd set contents of item 6 of d to "" & idx & " of " & recCount
- dd set enabled of items 4 thru 5 of d to [idx ≠ 1, idx ≠ recCount]
- set i to dd interact with user
- -- Store, New, Find, Prev, Next
- if i = 1 then
- PutRecord(idx, d)
- else if i = 2 then
- set dbData to dbData & dbNewRec
- set idx to dbData's length
- set recCount to idx
- GetRecord(idx, d)
- else if i = 3 then
- else if i = 4 then
- if idx > 1 then
- set idx to idx - 1
- GetRecord(idx, d)
- end if
- else if i = 5 then
- if idx < recCount then
- set idx to idx + 1
- GetRecord(idx, d)
- end if
- else if i = -1 then
- exit repeat
- end if
- end repeat
- dd uninstall
- return --result
-
- on GetRecord(idx, d)
- set AppleScript's text item delimiters to [tab]
- set dVals to text items of item idx of dbData
- dd set value of items 7 thru 16 of d to dVals
- set AppleScript's text item delimiters to []
- end GetRecord
-
- on PutRecord(idx, d)
- set dVals to dd get value of items 7 thru 16 of d
- set R to item 1 of dVals
- repeat with f in items 2 thru -1 of dVals
- set R to R & tab & f
- end repeat
- set item idx of dbData to R
- end PutRecord
-
- on Field(f, y)
- if f's style = text field then
- set R to DMake(text field, f's name, nameWidth, y, nWidth * (f's width), 12)
- return R & {name bounds:[10, 10 + y * lineV, 10 + nameWidth, 10 + y * lineV + 12]}
- --set r's name bounds to [10, 10 + y * lineV, 10 + nameWidth, 10 + y * lineV + 12]
- --return r
- else
- -- other field types
- end if
- end Field
-
- on DMake(T, n, x, y, w, h)
- set x to 10 + x
- set y to 10 + y * lineV
- return {class:T, bounds:[x, y, x + w, y + h], name:n}
- end DMake
-
- on MakeButton(n, i)
- return DMake(push button, n, (i - 1) * 60, lineCount - 1, 50, 20)
- --return DMake(push button, n, winH - 20 - (i - 1) * 60, lineCount - 1, 50, 20)
- end MakeButton